package com.yonyou.sto.modules.ims.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonyou.sto.modules.ims.mapper.ImsBillItemMapper;
import com.yonyou.sto.modules.ims.model.ImsBillItem;
import com.yonyou.sto.modules.ims.service.ImsBillItemService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aegon
 * @since 2020-10-10
 */
@Service
public class ImsBillItemServiceImpl extends ServiceImpl<ImsBillItemMapper, ImsBillItem> implements ImsBillItemService {

    @Override
    public boolean addBillItem(long id, String billSerial, List<Map<String, Object>> result) {

        result.forEach(re->{
            ImsBillItem item = new ImsBillItem();
            item.setBillId(id);
            item.setBillSerial(billSerial);
            item.setCreateTime(new Date());
            item.setProductQuantity(BigDecimal.valueOf((Double) re.get("xmsl")));
            item.setProductAmount(BigDecimal.valueOf((Double) re.get("xmje")));
            item.setProductName((String) re.get("xmmc"));
            item.setProductSpec((String) re.get("ggxh"));
            item.setProductUnit((String) re.get("dw"));
            item.setTaxPrice(BigDecimal.valueOf((Double) re.get("se")));
            item.setTaxRate(BigDecimal.valueOf((Double) re.get("sl")));
            item.setTaxAmount(BigDecimal.valueOf((Double) re.get("xmjshj")));
            item.setRowSn(Integer.valueOf(re.get("hh").toString()));
            item.setStatus(1);
            baseMapper.insert(item);
        });
        return true;
    }

    @Override
    public List<ImsBillItem> listByBillIds(List<Long> collect) {
        return baseMapper.listByBillIds(collect);
    }
}
